		TITLE	CFGPROC - Copyright (c) SLR Systems 1994

		INCLUDE	MACROS
		INCLUDE	IO_STRUC

		PUBLIC	FIND_PROCESS_CFG

		EXTERNDEF	OBJSTUFF:DWORD


		.DATA

		EXTERNDEF	INBUF:BYTE,OUTBUF:BYTE

		EXTERNDEF	CURN_FILE_LIST_GINDEX:DWORD,INPTR1:DWORD,CURN_COUNT:DWORD,ME_PTR:DWORD,CURN_INPTR:DWORD

		EXTERNDEF	INDNAM:NFN_STRUCT


		.CODE	STARTUP_TEXT

		EXTERNDEF	GETNST_SLASH:PROC,NEST_INDIRECT:PROC,HANDLE_EOF:PROC,_get_filename:proc
		EXTERNDEF	_do_findfirst:proc,ERR_RET:PROC,_close_findnext:proc

		EXTERNDEF	UNREC_IN_CFG_ERR:ABS


CFG_VARS	STRUC

CFG_TEMP_BP	DB	8 DUP(?)
;CFG_NFN_BP	NFN_STRUCT<>
CFG_OUTBUF_BP	DB	512 DUP(?)

CFG_VARS	ENDS

FIX	MACRO	X

X	EQU	([EBP].CFG_VARS.(X&_BP))

	ENDM

FIX	CFG_TEMP
;FIX	CFG_NFN
FIX	CFG_OUTBUF

CFG_NFN		EQU	(INDNAM)

FIND_PROCESS_CFG	PROC
		;
		;LOOK FOR OPTLINKS.CFG IN CURRENT DIRECTORY, ELSE IN HOME DIRECTORY
		;
		PUSH	EBP
		MOV	EAX,SIZE CFG_VARS
		MOV	EBP,ESP
		SUB	ESP,EAX
		SUB	EBP,EAX

		XOR	EAX,EAX
		MOV	EDX,OFF MY_NAME
		MOV	CURN_FILE_LIST_GINDEX,EAX
		PUSHM	EDI,ESI,EBX
		LEA	ECX,CFG_NFN
		MOV	EAX,OFF OBJSTUFF

		push	EDX
		push	ECX
		push	EAX
		call	_get_filename
		add	ESP,12

		LEA	EAX,CFG_NFN
		push	EAX
		call	_do_findfirst
		add	ESP,4
		test	EAX,EAX
		jnz	L2$
		;JNC	L2$
		;
		;TRY AGAIN USING HOME SEARCH PATH...
		;
		MOV	ESI,ME_PTR
		LEA	EDI,CFG_OUTBUF		;TEMP BUFFER...

		TEST	ESI,ESI
		JZ	L9$

		MOV	BPTR [EDI],'"'
		INC	EDI
L1$:
		MOV	AL,[ESI]
		INC	ESI
		MOV	[EDI],AL
		INC	EDI
		OR	AL,AL
		JNZ	L1$
		;
		;NOW BACK UP TO FIRST \ OR :
		;
		LEA	ESI,CFG_OUTBUF+1
		MOV	ECX,EDI
		SUB	ECX,ESI			;# OF CHARS TO CHECK
		JZ	L9$
L11$:
		MOV	AL,[EDI-1]
		DEC	EDI

		DEC	ECX
		JZ	L9$

		CMP	AL,'\'
		JZ	L13$

		CMP	AL,':'
		JNZ	L11$
L13$:
		MOV	BPTR [EDI+1],'"'
		INC	EDI

		MOV	ESI,OFF MY_NAME
		INC	EDI
L15$:
		MOV	AL,[ESI]
		INC	ESI
		MOV	[EDI],AL
		INC	EDI
		CMP	AL,0DH
		JNZ	L15$

		LEA	EDX,CFG_OUTBUF
		LEA	ECX,CFG_NFN
		MOV	EAX,OFF OBJSTUFF

		push	EDX
		push	ECX
		push	EAX
		call	_get_filename
		add	ESP,12

		LEA	EAX,CFG_NFN
		push	EAX
		call	_do_findfirst
		add	ESP,4
		test	EAX,EAX
		jnz	L2$
		;JNC	L2$
L9$:
		JMP	L99$

L2$:
		call	_close_findnext		;CLOSE HANDLE FOR NT
		;
		;FAKE POINTERS, ETC
		;
		MOV	EAX,CURN_INPTR
		MOV	EBX,CURN_COUNT
		PUSHM	EAX,EBX
		;
		;MARK EOF AT UNNESTING
		;
		LEA	EAX,CFG_TEMP
		MOV	ESI,OFF INBUF
		MOV	CURN_INPTR,EAX
		MOV	BPTR [EAX],1AH
		MOV	CURN_COUNT,1
		;
		;PUT CRLF IN CURRENT INBUF
		;
		MOV	INPTR1,ESI
		MOV	DPTR [ESI],0A0DH

		CALL	NEST_INDIRECT
		;
		;OK BOYS, WE START OFF IN OPTLINK SYNTAX MODE
		;
		SETT	DOING_CFG
L5$:
		CALL	GETNST_SLASH
		CMP	AL,0DH
		JZ	L5$
		CMP	AL,0AH
		JZ	L5$
		CMP	AL,';'
		JZ	L8$
		CMP	AL,1AH
		JZ	L8$
		;
		;UNRECOGNIZED JUNK IN .CFG FILE
		;
		MOV	AL,UNREC_IN_CFG_ERR
		CALL	ERR_RET
L8$:
		CALL	HANDLE_EOF

		POPM	CURN_COUNT,CURN_INPTR
		RESS	DOING_CFG
		RESS	INBUF_EOF
L99$:
		POPM	EBX,ESI,EDI
		LEA	ESP,[EBP + SIZE CFG_VARS]
		POP	EBP
		RET

FIND_PROCESS_CFG	ENDP


		.CONST

MY_NAME		DB	'OPTLINKS.CFG',0DH


		END

